"use strict";
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
const electron = require("electron");
const path = require("path");
const electronUpdater = require("electron-updater");
const fs = require("fs");
const http = require("http");
function _interopNamespaceDefault(e) {
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
  if (e) {
    for (const k in e) {
      if (k !== "default") {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}
const http__namespace = /* @__PURE__ */ _interopNamespaceDefault(http);
const defaultSettings = {
  window: {
    width: 1200,
    height: 800,
    isMaximized: false,
    isAlwaysOnTop: false
  },
  app: {
    theme: "auto",
    language: "zh-CN",
    autoStart: false,
    minimizeToTray: true,
    closeToTray: true
  },
  fileManager: {
    viewMode: "grid",
    sortBy: "name",
    sortOrder: "asc",
    showHiddenFiles: false
  },
  ai: {
    autoSave: true
  }
};
class SettingsManager {
  constructor() {
    __publicField(this, "settingsPath");
    __publicField(this, "settings");
    const userDataPath = electron.app.getPath("userData");
    this.settingsPath = path.join(userDataPath, "settings.json");
    if (!fs.existsSync(userDataPath)) {
      fs.mkdirSync(userDataPath, { recursive: true });
    }
    this.settings = this.loadSettings();
  }
  /**
   * 加载设置
   */
  loadSettings() {
    try {
      if (fs.existsSync(this.settingsPath)) {
        const data = fs.readFileSync(this.settingsPath, "utf-8");
        const loadedSettings = JSON.parse(data);
        return this.mergeSettings(defaultSettings, loadedSettings);
      }
    } catch (error) {
      console.error("加载设置失败:", error);
    }
    return { ...defaultSettings };
  }
  /**
   * 保存设置
   */
  saveSettings() {
    try {
      fs.writeFileSync(this.settingsPath, JSON.stringify(this.settings, null, 2), "utf-8");
      console.log("设置已保存:", this.settingsPath);
    } catch (error) {
      console.error("保存设置失败:", error);
    }
  }
  /**
   * 合并设置（深度合并）
   */
  mergeSettings(defaults, loaded) {
    const result = { ...defaults };
    for (const key in loaded) {
      if (loaded[key] && typeof loaded[key] === "object" && !Array.isArray(loaded[key])) {
        result[key] = this.mergeSettings(defaults[key] || {}, loaded[key]);
      } else {
        result[key] = loaded[key];
      }
    }
    return result;
  }
  /**
   * 获取所有设置
   */
  getSettings() {
    return { ...this.settings };
  }
  /**
   * 获取窗口设置
   */
  getWindowSettings() {
    return { ...this.settings.window };
  }
  /**
   * 更新窗口设置
   */
  updateWindowSettings(windowSettings) {
    this.settings.window = { ...this.settings.window, ...windowSettings };
    this.saveSettings();
  }
  /**
   * 获取应用设置
   */
  getAppSettings() {
    return { ...this.settings.app };
  }
  /**
   * 更新应用设置
   */
  updateAppSettings(appSettings) {
    this.settings.app = { ...this.settings.app, ...appSettings };
    this.saveSettings();
  }
  /**
   * 获取文件管理设置
   */
  getFileManagerSettings() {
    return { ...this.settings.fileManager };
  }
  /**
   * 更新文件管理设置
   */
  updateFileManagerSettings(fileManagerSettings) {
    this.settings.fileManager = { ...this.settings.fileManager, ...fileManagerSettings };
    this.saveSettings();
  }
  /**
   * 获取AI设置
   */
  getAISettings() {
    return { ...this.settings.ai };
  }
  /**
   * 更新AI设置
   */
  updateAISettings(aiSettings) {
    this.settings.ai = { ...this.settings.ai, ...aiSettings };
    this.saveSettings();
  }
  /**
   * 重置所有设置
   */
  resetSettings() {
    this.settings = { ...defaultSettings };
    this.saveSettings();
  }
  /**
   * 导出设置
   */
  exportSettings() {
    return JSON.stringify(this.settings, null, 2);
  }
  /**
   * 导入设置
   */
  importSettings(settingsJson) {
    try {
      const importedSettings = JSON.parse(settingsJson);
      this.settings = this.mergeSettings(defaultSettings, importedSettings);
      this.saveSettings();
      return true;
    } catch (error) {
      console.error("导入设置失败:", error);
      return false;
    }
  }
}
const settingsManager = new SettingsManager();
class RickPanApp {
  constructor() {
    __publicField(this, "mainWindow", null);
    __publicField(this, "tray", null);
    __publicField(this, "isDev", process.env.NODE_ENV === "development");
    this.initApp();
  }
  /**
   * 初始化应用
   */
  initApp() {
    if (process.platform === "win32") {
      electron.app.setAppUserModelId("com.rickpan.app");
    }
    electron.app.whenReady().then(() => {
      this.createWindow();
      this.setupIPC();
      this.setupMenu();
      this.setupTray();
      this.setupGlobalShortcuts();
      this.setupAutoUpdater();
    });
    electron.app.on("window-all-closed", () => {
      if (process.platform !== "darwin") {
        console.log("所有窗口已关闭，应用继续在托盘运行");
      }
    });
    electron.app.on("before-quit", (event) => {
      if (!electron.app.isQuiting) {
        event.preventDefault();
        electron.app.isQuiting = true;
        this.clearUserOnlineStatus().then(() => {
          electron.globalShortcut.unregisterAll();
          if (this.tray) {
            this.tray.destroy();
            this.tray = null;
          }
          electron.app.quit();
        }).catch((error) => {
          console.error("清除在线状态失败，强制退出:", error);
          electron.globalShortcut.unregisterAll();
          if (this.tray) {
            this.tray.destroy();
            this.tray = null;
          }
          electron.app.quit();
        });
      }
    });
    electron.app.on("activate", () => {
      if (electron.BrowserWindow.getAllWindows().length === 0) {
        this.createWindow();
      }
    });
  }
  /**
   * 创建主窗口
   */
  createWindow() {
    const windowSettings = settingsManager.getWindowSettings();
    this.mainWindow = new electron.BrowserWindow({
      width: windowSettings.width,
      height: windowSettings.height,
      x: windowSettings.x,
      y: windowSettings.y,
      minWidth: 800,
      minHeight: 600,
      show: false,
      // 先隐藏，加载完成后显示
      frame: false,
      // 🔑 禁用原生标题栏，使用自定义标题栏
      icon: path.join(__dirname, "../build/icon.png"),
      webPreferences: {
        nodeIntegration: false,
        contextIsolation: true,
        enableRemoteModule: false,
        preload: path.join(__dirname, "preload.cjs"),
        webSecurity: true
      },
      titleBarStyle: process.platform === "darwin" ? "hiddenInset" : "hidden"
    });
    if (windowSettings.isMaximized) {
      this.mainWindow.maximize();
    }
    if (windowSettings.isAlwaysOnTop) {
      this.mainWindow.setAlwaysOnTop(true);
    }
    if (this.isDev) {
      this.mainWindow.loadURL("http://localhost:5173");
      this.mainWindow.webContents.openDevTools();
    } else {
      this.mainWindow.loadFile(path.join(__dirname, "../dist/index.html"));
    }
    this.mainWindow.once("ready-to-show", () => {
      var _a, _b;
      (_a = this.mainWindow) == null ? void 0 : _a.show();
      if (this.isDev) {
        (_b = this.mainWindow) == null ? void 0 : _b.webContents.openDevTools();
      }
    });
    this.setupWindowStateListeners();
    this.mainWindow.on("close", (event) => {
      var _a;
      if (!electron.app.isQuiting) {
        event.preventDefault();
        const { dialog: dialog2 } = require("electron");
        const choice = dialog2.showMessageBoxSync(this.mainWindow, {
          type: "question",
          buttons: ["最小化到托盘", "退出应用", "取消"],
          defaultId: 0,
          title: "RickPan",
          message: "您想要最小化到托盘还是退出应用？",
          detail: "最小化到托盘：应用继续在后台运行\n退出应用：完全关闭应用并清除在线状态"
        });
        if (choice === 0) {
          (_a = this.mainWindow) == null ? void 0 : _a.hide();
        } else if (choice === 1) {
          electron.app.isQuiting = true;
          this.clearUserOnlineStatus().then(() => {
            electron.app.quit();
          }).catch(() => {
            electron.app.quit();
          });
        }
      }
    });
  }
  /**
   * 设置窗口状态监听
   */
  setupWindowStateListeners() {
    if (!this.mainWindow) return;
    let saveTimeout;
    const debouncedSave = () => {
      clearTimeout(saveTimeout);
      saveTimeout = setTimeout(() => {
        this.saveWindowState();
      }, 500);
    };
    this.mainWindow.on("resize", debouncedSave);
    this.mainWindow.on("move", debouncedSave);
    this.mainWindow.on("maximize", () => {
      settingsManager.updateWindowSettings({ isMaximized: true });
    });
    this.mainWindow.on("unmaximize", () => {
      settingsManager.updateWindowSettings({ isMaximized: false });
      debouncedSave();
    });
    this.mainWindow.on("always-on-top-changed", (_, isAlwaysOnTop) => {
      settingsManager.updateWindowSettings({ isAlwaysOnTop });
    });
  }
  /**
   * 保存窗口状态
   */
  saveWindowState() {
    if (!this.mainWindow || this.mainWindow.isMaximized()) return;
    const bounds = this.mainWindow.getBounds();
    settingsManager.updateWindowSettings({
      width: bounds.width,
      height: bounds.height,
      x: bounds.x,
      y: bounds.y
    });
  }
  /**
   * 设置IPC通信
   */
  setupIPC() {
    electron.ipcMain.handle("file:select", this.handleFileSelect.bind(this));
    electron.ipcMain.handle("file:selectFolder", this.handleFolderSelect.bind(this));
    electron.ipcMain.handle("file:save", this.handleFileSave.bind(this));
    electron.ipcMain.handle("app:minimize", () => {
      var _a;
      return (_a = this.mainWindow) == null ? void 0 : _a.minimize();
    });
    electron.ipcMain.handle("app:maximize", () => {
      var _a, _b;
      if ((_a = this.mainWindow) == null ? void 0 : _a.isMaximized()) {
        this.mainWindow.unmaximize();
      } else {
        (_b = this.mainWindow) == null ? void 0 : _b.maximize();
      }
    });
    electron.ipcMain.handle("app:close", () => {
      var _a;
      return (_a = this.mainWindow) == null ? void 0 : _a.close();
    });
    electron.ipcMain.handle("app:hide", () => {
      var _a;
      return (_a = this.mainWindow) == null ? void 0 : _a.hide();
    });
    electron.ipcMain.handle("app:show", () => {
      var _a, _b;
      (_a = this.mainWindow) == null ? void 0 : _a.show();
      (_b = this.mainWindow) == null ? void 0 : _b.focus();
    });
    electron.ipcMain.handle("app:isMaximized", () => {
      var _a;
      return ((_a = this.mainWindow) == null ? void 0 : _a.isMaximized()) || false;
    });
    electron.ipcMain.handle("system:openExternal", (_, url) => electron.shell.openExternal(url));
    electron.ipcMain.handle("system:showItemInFolder", (_, path2) => electron.shell.showItemInFolder(path2));
    electron.ipcMain.handle("notification:show", this.handleShowNotification.bind(this));
    electron.ipcMain.handle("settings:get", () => settingsManager.getSettings());
    electron.ipcMain.handle("settings:getWindow", () => settingsManager.getWindowSettings());
    electron.ipcMain.handle("settings:getApp", () => settingsManager.getAppSettings());
    electron.ipcMain.handle("settings:getFileManager", () => settingsManager.getFileManagerSettings());
    electron.ipcMain.handle("settings:getAI", () => settingsManager.getAISettings());
    electron.ipcMain.handle("settings:updateWindow", (_, settings) => settingsManager.updateWindowSettings(settings));
    electron.ipcMain.handle("settings:updateApp", (_, settings) => settingsManager.updateAppSettings(settings));
    electron.ipcMain.handle("settings:updateFileManager", (_, settings) => settingsManager.updateFileManagerSettings(settings));
    electron.ipcMain.handle("settings:updateAI", (_, settings) => settingsManager.updateAISettings(settings));
    electron.ipcMain.handle("settings:reset", () => settingsManager.resetSettings());
    electron.ipcMain.handle("settings:export", () => settingsManager.exportSettings());
    electron.ipcMain.handle("settings:import", (_, settingsJson) => settingsManager.importSettings(settingsJson));
    electron.ipcMain.handle("window:toggleAlwaysOnTop", () => {
      if (this.mainWindow) {
        const isOnTop = this.mainWindow.isAlwaysOnTop();
        this.mainWindow.setAlwaysOnTop(!isOnTop);
        return !isOnTop;
      }
      return false;
    });
    electron.ipcMain.handle("window:setAlwaysOnTop", (_, alwaysOnTop) => {
      if (this.mainWindow) {
        this.mainWindow.setAlwaysOnTop(alwaysOnTop);
        return alwaysOnTop;
      }
      return false;
    });
    electron.ipcMain.handle("updater:check", () => electronUpdater.autoUpdater.checkForUpdatesAndNotify());
    electron.ipcMain.handle("updater:download", () => electronUpdater.autoUpdater.downloadUpdate());
    electron.ipcMain.handle("updater:install", () => electronUpdater.autoUpdater.quitAndInstall());
  }
  /**
   * 处理文件选择
   */
  async handleFileSelect() {
    const result = await electron.dialog.showOpenDialog(this.mainWindow, {
      properties: ["openFile", "multiSelections"],
      filters: [
        { name: "All Files", extensions: ["*"] },
        { name: "Images", extensions: ["jpg", "jpeg", "png", "gif", "bmp", "webp"] },
        { name: "Documents", extensions: ["pdf", "doc", "docx", "txt", "md"] },
        { name: "Videos", extensions: ["mp4", "avi", "mov", "wmv", "flv"] },
        { name: "Audio", extensions: ["mp3", "wav", "flac", "aac"] }
      ]
    });
    return result.filePaths;
  }
  /**
   * 处理文件夹选择
   */
  async handleFolderSelect() {
    const result = await electron.dialog.showOpenDialog(this.mainWindow, {
      properties: ["openDirectory"]
    });
    return result.filePaths[0] || null;
  }
  /**
   * 处理文件保存
   */
  async handleFileSave(_, data, defaultPath) {
    const result = await electron.dialog.showSaveDialog(this.mainWindow, {
      defaultPath,
      filters: [
        { name: "All Files", extensions: ["*"] }
      ]
    });
    if (!result.canceled && result.filePath) {
      return result.filePath;
    }
    return null;
  }
  /**
   * 显示关于对话框
   */
  showAboutDialog() {
    const iconPath = this.isDev ? path.join(__dirname, "../../public/favicon-32x32.png") : path.join(process.resourcesPath, "app/dist/favicon-32x32.png");
    electron.dialog.showMessageBox(this.mainWindow, {
      type: "info",
      title: "关于 RickPan",
      message: "RickPan",
      detail: `版本: ${electron.app.getVersion()}

企业级云存储解决方案
支持文件管理、AI助手、工作报告等功能

© 2025 RickPan Team`,
      buttons: ["确定"],
      defaultId: 0,
      icon: iconPath
    });
  }
  /**
   * 处理系统通知
   */
  handleShowNotification(_, options) {
    try {
      if (electron.Notification.isSupported()) {
        const iconPath = options.icon || (this.isDev ? path.join(__dirname, "../../public/favicon-32x32.png") : path.join(process.resourcesPath, "app/dist/favicon-32x32.png"));
        const notification = new electron.Notification({
          title: options.title || "RickPan",
          body: options.body || "",
          icon: iconPath,
          silent: options.silent || false
        });
        notification.on("click", () => {
          var _a;
          this.showMainWindow();
          if (options.action) {
            (_a = this.mainWindow) == null ? void 0 : _a.webContents.send("notification:action", options.action);
          }
        });
        notification.show();
        if (options.autoClose && options.autoClose > 0) {
          setTimeout(() => {
            notification.close();
          }, options.autoClose);
        }
      } else {
        console.warn("系统不支持通知功能");
      }
    } catch (error) {
      console.error("显示通知失败:", error);
    }
  }
  /**
   * 设置应用菜单
   */
  setupMenu() {
    const template = [
      {
        label: "文件",
        submenu: [
          {
            label: "上传文件",
            accelerator: "CmdOrCtrl+O",
            click: () => {
              this.handleFileSelect();
            }
          },
          { type: "separator" },
          {
            label: "退出",
            accelerator: process.platform === "darwin" ? "Cmd+Q" : "Ctrl+Q",
            click: () => {
              electron.app.quit();
            }
          }
        ]
      },
      {
        label: "视图",
        submenu: [
          {
            label: "刷新",
            accelerator: "F5",
            role: "reload"
          },
          {
            label: "强制重新加载",
            role: "forceReload"
          },
          {
            label: "开发者工具",
            role: "toggleDevTools"
          },
          { type: "separator" },
          {
            label: "实际大小",
            role: "resetZoom"
          },
          {
            label: "放大",
            role: "zoomIn"
          },
          {
            label: "缩小",
            role: "zoomOut"
          },
          { type: "separator" },
          {
            label: "全屏",
            role: "togglefullscreen"
          }
        ]
      },
      {
        label: "窗口",
        submenu: [
          {
            label: "最小化",
            role: "minimize"
          },
          {
            label: "关闭",
            role: "close"
          },
          { type: "separator" },
          {
            label: "置顶",
            type: "checkbox",
            checked: settingsManager.getWindowSettings().isAlwaysOnTop,
            click: (menuItem) => {
              var _a;
              (_a = this.mainWindow) == null ? void 0 : _a.setAlwaysOnTop(menuItem.checked);
              settingsManager.updateWindowSettings({ isAlwaysOnTop: menuItem.checked });
            }
          }
        ]
      },
      {
        label: "帮助",
        submenu: [
          {
            label: "快捷键帮助",
            accelerator: "F1",
            click: () => {
              var _a;
              (_a = this.mainWindow) == null ? void 0 : _a.webContents.send("menu:shortcuts-help");
            }
          },
          {
            label: "用户手册",
            click: () => {
              electron.shell.openExternal("https://rickpan.com/docs");
            }
          },
          {
            label: "反馈问题",
            click: () => {
              electron.shell.openExternal("https://github.com/rickpan/issues");
            }
          },
          { type: "separator" },
          {
            label: "检查更新",
            click: () => {
              var _a;
              (_a = this.mainWindow) == null ? void 0 : _a.webContents.send("menu:check-updates");
            }
          },
          {
            label: "关于 RickPan",
            click: () => {
              this.showAboutDialog();
            }
          }
        ]
      }
    ];
    const menu = electron.Menu.buildFromTemplate(template);
    electron.Menu.setApplicationMenu(menu);
  }
  /**
   * 设置系统托盘
   */
  setupTray() {
    const possiblePaths = [
      path.join(__dirname, "../../public/favicon-32x32.png"),
      path.join(__dirname, "../../public/pwa-192x192.png"),
      path.join(__dirname, "../public/favicon-32x32.png"),
      path.join(process.cwd(), "public/favicon-32x32.png"),
      path.join(process.cwd(), "public/pwa-192x192.png")
    ];
    let trayIconPath = "";
    for (const path2 of possiblePaths) {
      try {
        if (require("fs").existsSync(path2)) {
          trayIconPath = path2;
          console.log("找到托盘图标:", path2);
          break;
        }
      } catch (e) {
        continue;
      }
    }
    if (!trayIconPath) {
      console.error("未找到托盘图标文件");
      return;
    }
    try {
      console.log("正在创建系统托盘...");
      this.tray = new electron.Tray(trayIconPath);
      const contextMenu = electron.Menu.buildFromTemplate([
        {
          label: "显示 RickPan",
          click: () => {
            console.log("托盘菜单：显示窗口");
            this.showMainWindow();
          }
        },
        { type: "separator" },
        {
          label: "上传文件",
          click: () => {
            console.log("托盘菜单：上传文件");
            this.handleFileSelect();
          }
        },
        { type: "separator" },
        {
          label: "关于 RickPan",
          click: () => {
            console.log("托盘菜单：关于");
            this.showAboutDialog();
          }
        },
        {
          label: "退出",
          click: () => {
            console.log("托盘菜单：退出");
            electron.app.isQuiting = true;
            this.clearUserOnlineStatus().then(() => {
              electron.app.quit();
            }).catch(() => {
              electron.app.quit();
            });
          }
        }
      ]);
      this.tray.setToolTip("RickPan - 企业级云存储");
      this.tray.setContextMenu(contextMenu);
      this.tray.on("double-click", () => {
        console.log("托盘双击：显示窗口");
        this.showMainWindow();
      });
      this.tray.on("right-click", () => {
        var _a;
        console.log("托盘右键点击");
        (_a = this.tray) == null ? void 0 : _a.popUpContextMenu();
      });
      console.log("系统托盘创建成功");
    } catch (error) {
      console.error("创建系统托盘失败:", error);
    }
  }
  /**
   * 显示主窗口
   */
  showMainWindow() {
    if (this.mainWindow) {
      if (this.mainWindow.isMinimized()) {
        this.mainWindow.restore();
      }
      this.mainWindow.show();
      this.mainWindow.focus();
    }
  }
  /**
   * 处理截图上传
   */
  async handleScreenshot() {
    try {
      this.handleShowNotification(null, {
        title: "RickPan",
        body: "截图上传功能正在开发中..."
      });
    } catch (error) {
      console.error("截图失败:", error);
    }
  }
  /**
   * 处理全局刷新
   */
  handleGlobalRefresh() {
    try {
      if (this.mainWindow) {
        if (this.mainWindow.isMinimized()) {
          this.mainWindow.restore();
        }
        this.mainWindow.show();
        this.mainWindow.focus();
        this.mainWindow.webContents.reload();
        console.log("执行全局刷新");
      }
    } catch (error) {
      console.error("全局刷新失败:", error);
    }
  }
  /**
   * 设置全局快捷键
   */
  setupGlobalShortcuts() {
    try {
      electron.globalShortcut.register("CommandOrControl+Shift+S", () => {
        this.handleScreenshot();
      });
      electron.globalShortcut.register("CommandOrControl+Shift+R", () => {
        this.handleGlobalRefresh();
      });
      electron.globalShortcut.register("F5", () => {
        this.handleGlobalRefresh();
      });
      console.log("全局快捷键注册成功");
    } catch (error) {
      console.error("注册全局快捷键失败:", error);
    }
  }
  /**
   * 设置自动更新
   */
  setupAutoUpdater() {
    if (this.isDev) {
      return;
    }
    electronUpdater.autoUpdater.checkForUpdatesAndNotify();
    electronUpdater.autoUpdater.on("update-available", () => {
      var _a;
      (_a = this.mainWindow) == null ? void 0 : _a.webContents.send("update-available");
    });
    electronUpdater.autoUpdater.on("update-downloaded", () => {
      var _a;
      (_a = this.mainWindow) == null ? void 0 : _a.webContents.send("update-downloaded");
    });
  }
  /**
   * 清除用户在线状态
   */
  async clearUserOnlineStatus() {
    return new Promise(async (resolve, reject) => {
      var _a;
      try {
        const token = await ((_a = this.mainWindow) == null ? void 0 : _a.webContents.executeJavaScript(`
          localStorage.getItem('token');
        `));
        if (!token) {
          console.log("⚠️ 用户未登录，无需清除在线状态");
          resolve();
          return;
        }
        const postData = JSON.stringify({});
        const options = {
          hostname: "localhost",
          port: 8080,
          path: "/api/auth/logout",
          method: "POST",
          headers: {
            "Authorization": `Bearer ${token}`,
            "Content-Type": "application/json",
            "Content-Length": Buffer.byteLength(postData)
          },
          timeout: 5e3
          // 5秒超时
        };
        const req = http__namespace.request(options, (res) => {
          console.log(`在线状态清除请求响应: ${res.statusCode}`);
          let data = "";
          res.on("data", (chunk) => {
            data += chunk;
          });
          res.on("end", () => {
            if (res.statusCode === 200) {
              console.log("✅ 用户在线状态清除成功");
            } else {
              console.log(`⚠️ 在线状态清除响应异常: ${res.statusCode}`);
            }
            resolve();
          });
        });
        req.on("error", (error) => {
          console.error("❌ 清除用户在线状态请求失败:", error.message);
          resolve();
        });
        req.on("timeout", () => {
          console.error("❌ 清除用户在线状态请求超时");
          req.destroy();
          resolve();
        });
        req.write(postData);
        req.end();
      } catch (error) {
        console.error("❌ 清除用户在线状态失败:", error);
        resolve();
      }
    });
  }
}
new RickPanApp();
